package cn.jiyun.controller;

//import cn.jiyun.common.AutoLogs;
import cn.jiyun.common.config.Result;
import cn.jiyun.entity.Yddgl;
import cn.jiyun.entity.Yddqx;
import cn.jiyun.mapper.YddqxMapper;
import cn.jiyun.service.YddglService;
import cn.jiyun.service.YddqxService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/yddgl")
@CrossOrigin //允许跨域
public class YddglController {
    @Autowired
    private YddglService yddglService;

    @Autowired
    private YddqxMapper yddqxMapper;
    @RequestMapping("/findPage")
    public Result findPage(Integer pageNum, Integer pageSize, @RequestBody Yddgl yddgl){
        Page page = yddglService.findPage(pageNum, pageSize, yddgl);
        return Result.ok(page);
    }

    @RequestMapping("findQname")
    public Result findQname(){
        List<Yddqx> list = yddqxMapper.selectList(null);
        return Result.ok(list);
    }

    @RequestMapping("/deleteById")
//    @AutoLogs(value = "移动端管理删除操作", loggingtype  = 0)
    public Result deleteById(Integer id){
        yddglService.removeById(id);
        return Result.ok("删除成功！");
    }

    @RequestMapping("findById")
    public Result findById(Integer id){
        Yddgl yddgl = yddglService.findById(id);
        return Result.ok(yddgl);
    }

    @RequestMapping("add")
//    @AutoLogs(value = "移动端管理添加操作", loggingtype  = 0)
    public Result add(@RequestBody Yddgl yddgl){
        if (yddgl.getId()==null){
            yddglService.save(yddgl);
        }else {
            yddglService.updateById(yddgl);
        }
        return Result.ok("操作成功！");
    }



}
